package com.zxbit.uangstore.presenter;

import com.zxbit.uangstore.base.BasePresenter;
import com.zxbit.uangstore.business.CustomConsumer;
import com.zxbit.uangstore.cache.UserInfo;
import com.zxbit.uangstore.constant.ParamsFactory;
import com.zxbit.uangstore.domain.BlankResponse;
import com.zxbit.uangstore.domain.LoginResponse;
import com.zxbit.uangstore.domain.ProductResponse;
import com.zxbit.uangstore.mvpview.MineMvpView;
import com.zxbit.uangstore.network.RetrofitManager;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class MinePresenter extends BasePresenter {
    private MineMvpView mvpView;

    public MinePresenter(MineMvpView mvpView) {
        this.mvpView = mvpView;
    }

    public void getHistory() {
        toSubScribe(req.getHistory(UserInfo.getToken(), ParamsFactory.getCommonParams(null)),
                new CustomConsumer<ProductResponse>() {
            @Override
            protected void processCommonData(ProductResponse productResponse) {
                mvpView.onGetDataNext(productResponse);
            }
        }, new Consumer<Throwable>() {
            @Override
            public void accept(Throwable throwable) throws Exception {
                mvpView.onGetDataError(throwable);
            }
        });
    }

    public void deleteHistory(String productId) {
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("id", productId);
        toSubScribe(req.deleteHistory(UserInfo.getToken(), ParamsFactory.getCommonParams(paramsMap)),
                new CustomConsumer<BlankResponse>() {
                    @Override
                    protected void processCommonData(BlankResponse blankResponse) {
                        mvpView.onGetDataNext(blankResponse);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mvpView.onGetDataError(throwable);
                    }
                });
    }
}
